package com.urun.interceptor.hotanalysis.controller;

import com.alibaba.fastjson.JSONObject;

import com.urun.interceptor.hotanalysis.DTO.RankSearchDTO;
import com.urun.interceptor.hotanalysis.bean.Result;
import com.urun.interceptor.hotanalysis.service.RankSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 搜索排行榜
 * @author zqz
 * @date 2022/4/2 17:30
 */
@RestController
@RequestMapping("/Rank")
@CrossOrigin(origins = "*",maxAge = 3600)
@Api(tags = "二次检索")
public class RankSearchController {

    @Autowired
    RankSearchService rankSearchService;

//    @GetMapping("/RankSearch")
//    public Result RankSearch(){
//        Result result = new Result();
//        List<RankSearchDTO> rankSearchDTOS = rankSearchService.searchDTOS();
//        if (rankSearchDTOS.isEmpty()){
//            return new Result("404","没有该关键字的数据",null);
//        }else {
//            result.setMessage("搜索成功");
//            result.setCode("200");
//            result.setData(rankSearchDTOS);
//        }
//        return result;
//    }

    @ApiOperation(value = "二次检索",notes = "通过Input，ListingTime__gt，ListingTime__lt，PlanID来二次检索含有关键字的；返回字段为rowNum,word,sourceName,trend，discussNumber，hotNumber，maxRanking，listingTime;请求方式:POST,支持格式:application/json")
    @PostMapping("/RankSearchLike")
    public Result RankSearchLike(@RequestBody JSONObject obj){
        String input = obj.getString("Input");
        String beginTime = obj.getString("ListingTime__gt");
        String endTime = obj.getString("ListingTime__lt");
        Integer planID = obj.getInteger("PlanID");
        String str = "%" + input + "%";
        Result result = new Result();
        List<RankSearchDTO> rankSearchDTOS = rankSearchService.serchDtosLike(str, beginTime, endTime,planID);
        if (rankSearchDTOS.isEmpty()){
            return new Result("404","没有该关键字的数据",null);
        }else {
            result.setMessage("搜索成功");
            result.setCode("200");
            result.setData(rankSearchDTOS);
        }
        return result;

    }

}
